package il.ac.braude.sona.gui;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JPanel;
/**
 * The ButtonPanel contains all methods to create GUI button panel and add buttens to it
 * @author  Ofek Ron
 * @author Avihay Avitan
 * @author Nitzan Inbar
 * @author Sasha Rozenthal
 * Laboratory in Software Engineering,Ort Braude College.</p>
 *
 */
public class ButtonPanel extends JPanel {
	private GridBagConstraints con;
	public ButtonPanel() {
		setLayout(new GridBagLayout());
		con = new GridBagConstraints();
		con.gridy=0;
		con.gridwidth=3;
		con.gridx=1;
		con.fill=GridBagConstraints.HORIZONTAL;
		con.ipady = 10;
		con.insets.set(10, 0, 10, 0);
	}
	/**
	 * add button to this button panel
	 * @param buttonTitle
	 * @param listener
	 */
	public void addButton(String buttonTitle,ActionListener listener) {
		JButton button = new JButton(buttonTitle);
		button.addActionListener(listener);
		con.insets.set(0, 0, 10, 0);
		add(button,con);
		con.gridy++;
	}
	/**
	 * add button to this button panel
	 * @param button
	 * @param listener
	 */
	public void addButton(AbstractButton button,ActionListener listener) {
		button.addActionListener(listener);
		con.insets.set(0, 0, 10, 0);
		add(button,con);
		con.gridy++;
	}
	@Override
	public Component add(Component comp) {
		con.insets.set(0, 0, 10, 0);
		add(comp,con);
		con.gridy++;
		return comp;
	}
}
